nwnfandomcom-20200213-history
Talk:OnHeartbeat event
PC check Having been corrected by Lightfoot8 in the scripter's forum, it was shown that heart beats do not check the presence of a PC in the area. They will always fire once every 6 seconds (excepting inactive encounters). WhiZard 23:58, December 11, 2011 (UTC) * If you were going by this article, I guess I should apologize (at least a little, even though someone else wrote the article). I have (for years) known that heartbeats fire regardless of the presence of PCs (it was kind of crucial to this from 2007), but I never noticed, or never got around to editing, this article. Although, I wonder if you carefully checked the "six seconds" part? As I recall, I was not timing the firings, but they did seem to fire less often in areas without PCs, maybe 50% slower (every 9 seconds)? Or maybe that was just creature heartbeats. Or just sloppy perception on my part. Eh, calling it "every six seconds" is probably good enough unless someone wants to do some timing tests. --The Krit 01:53, December 12, 2011 (UTC) :* I'm getting for creatures 6 seconds from inside a PC area and around 8-9 seconds outside. But for triggers and placables I'm getting 6 seconds regardless. I'll test a few more. WhiZard 05:19, December 12, 2011 (UTC) ::* That does make some degree of sense. When the last PC leaves an area, creatures using the default AI level get switched down to low AI. So it would not be a stretch for BioWare to slow down their heartbeats at the same time. Other objects do not have an AI, so they would not be part of that loop (presumably a loop is used for this), so would not have their heartbeats slowed. And given how little BioWare used heartbeats for non-creatures, they would have no reason to go through the trouble of expanding that loop to include non-creatures. At least that's a plausible explanation for what you are seeing (and it is likely that I was only looking at creature heartbeats when I noticed a slowdown). Eh, might be worth adding to the article. --The Krit 21:59, December 12, 2011 (UTC) :::* Looks like you nailed it. Creatures with AI_LEVEL_HIGH maintain their heartbeat fire rate. WhiZard 23:51, December 12, 2011 (UTC) :::* Krit could the Default/Invalid AI be possibly registering as AI_LEVEL_VERY_LOW when PCs exit the area. Very Low AI has a 9 second heartbeat regardless of whether PCs are in the area or not. All other levels use the 6 second heartbeat, with default/invalid 6 seconds in a PC area and 9 seconds otherwise. WhiZard 05:51, December 13, 2011 (UTC) ::::* Yeah, it probably is more related to the AI setting than actually a PC being in the area. (Actually, that occurred to me, but it looks like you tested it before I got the chance.) --The Krit 17:45, December 13, 2011 (UTC) :::* Looking at the scripting command GetAILevel(). For creatures whose AI is set as default (-1) this will return 1 (low AI) in a PC area and 0 (very low AI) in an area without PCs. It does not return -1 if the creature is using default AI. WhiZard 06:02, December 13, 2011 (UTC) ::::* That is how the command is supposed to work. GetAILevel() returns the creature's current AI level, which is different than its AI "setting" when the "setting" is "default". (As far as I know, I just invented this "setting" terminology, but it fits.) The way BioWare uses that command (in the default heartbeat script) indicates that BioWare had no interest in differentiating between a "low" AI due to PCs in the area and a "low" AI due to an explicit setting via SetAILevel(). As long as the AI is low (for whatever reason), it should act with low-level AI. Similarly for the other AI levels. --The Krit 17:45, December 13, 2011 (UTC) ::::* OK, since writing the above, I've taken a look at the Lexicon entry for GetAILevel() and seen that there it is suggested that the command would return AI_LEVEL_DEFAULT. So there is a reason for someone to think (incorrectly) that is the case. The Lexicon is a good reference, but it is not always right. On the other hand, going by BioWare's scripts is another good reference that is not always right, but in this case I have relevant personal experience. (I've seen user-defined heartbeats not firing when no PC was in the area, and traced it to the AI check in the standard script.) Nothing beats testing things out. ;) --The Krit 22:56, December 13, 2011 (UTC) * Based on the above, I figured this was a good excuse to document the AI commands in this wiki. ;) --The Krit 18:51, December 13, 2011 (UTC)